package org.msb.accentis.data.adapters;

import java.math.BigDecimal;
import java.util.Date;

import org.msb.accentis.data.pojo.Account;
import org.msb.accentis.data.pojo.Category;
import org.msb.accentis.data.pojo.Individual;
import org.msb.accentis.data.pojo.Payee;
import org.msb.accentis.data.pojo.Transaction;
import org.msb.accentis.data.pojo.TransactionDetail;

public class AccountTransactionAdapter implements Comparable<AccountTransactionAdapter> {

	private Account account;
	
	private Transaction transaction;
	
	private BigDecimal balance = BigDecimal.ZERO;
	
	public AccountTransactionAdapter(Account account, Transaction transaction) {
		this.account = account;
		this.transaction = transaction;
	}
	
	public Date getDate() {
		return transaction.getDate();
	}
	
	public String getReference() {
		return transaction.getReference();
	}
	
	public Payee getPayee() {
		for (TransactionDetail detail : transaction.getTransactionDetails())
			if (account.equals(detail.getAccount()))
				if (null != detail.getPayee())
					return detail.getPayee();
		
		return null;
	}
	
	public Individual getIndividual() {
		for (TransactionDetail detail : transaction.getTransactionDetails())
			if (account.equals(detail.getAccount()))
				if (null != detail.getIndividual())
					return detail.getIndividual();
		
		return null;
	}
	
	public Category getCategory() {
		for (TransactionDetail detail : transaction.getTransactionDetails())
			if (account.equals(detail.getAccount()))
				if (null != detail.getCategory())
					return detail.getCategory();
		
		return null;
	}
	
	public String getDescription() {
		return transaction.getDescription();
	}
	
	public BigDecimal getAmount() {
		BigDecimal amount = BigDecimal.ZERO;
		for (TransactionDetail detail : transaction.getTransactionDetails())
			if (account.equals(detail.getAccount()))
				amount = amount.add(detail.getAmount());
		
		return amount;
	}
	
	public BigDecimal getBalance() {
		return balance;
	}
	
	public Transaction getTransaction() {
		return transaction;
	}
	
	@Override
	public int compareTo(AccountTransactionAdapter other) {
		return 0;
	}
}
